package com.sudu.config;

import com.sudu.controller.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {

    @Autowired
    private TokenInterceptor tokenInterceptor ;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 设置 非 springMvc 访问的路径
        // 当 访问 /pages/？？？  （某静态资源）时 ，不走 MVC
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/") ;
        registry.addResourceHandler("/css/**").addResourceLocations("/css/") ;
        registry.addResourceHandler("/js/**").addResourceLocations("/js/") ;
        registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/") ;
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        //添加默认的静态资源访问路径
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:static/","classpath:META-IFA/resources/","classpath:resources/","classpath:public/","classpath:/");
        registry.addResourceHandler("/image/**") //虚拟url路径
                .addResourceLocations("file:/home/bilibili/bili/image/"); //真实本地路径
        registry.addResourceHandler("/cover/**") //虚拟url路径
                .addResourceLocations("file:/home/bilibili/bili/cover/"); //真实本地路径
        registry.addResourceHandler("/video/**") //虚拟url路径
                .addResourceLocations("file:/home/bilibili/bili/video/"); //真实本地路径


    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/users/**" ) ;
    }
}
